import React from 'react';
import { observer } from 'mobx-react';
import { WeaUpload ,WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

interface Props {
  value?: string;
  valueSpan?: string;
  onChange: any;
  uploadMap:any;
  fieldtype:string;
  viewAttr:string;
  key:string;
}

@observer
export default class Upload extends React.Component<Props, any> {

  render() {
    const {uploadMap,fieldtype,key,viewAttr} = this.props;

        let main ;
        let sub ;
        let sec;
        let categoryStr;
        let uploadUrl ;
        let maxUploadSize ;
        let mes ;
        const baseProps: any = {};
        /**
                categoryType  0:固定目录   1：选择目录    9：默认设置
                fileFormat   文档限制格式
        */
       if(!uploadMap.categoryType||uploadMap.categoryType==""){
        mes =  getLabel(388817,"附件上传目录未设置!");   
      }else if(uploadMap.categoryType=='1'){//选择目录
              mes=getLabel(500335,"附件上传目录为选择目录，不支持批量操作")+"!";
            }else{              
                main = uploadMap.mainCategory;
                sub = uploadMap.subCategory;
                sec = uploadMap.secCategory;
                if((uploadMap.categoryType=='9'&&main<=0&&sub<=0&&sec<=0)||(uploadMap.categoryType=='0'&&main<=0&&sub<=0&&sec<=0)){//没有设置目录
                    mes =  getLabel(388817,"附件上传目录未设置!");
                }else{             
                    categoryStr= main + "," + sub + "," + sec;
                    uploadUrl = "/api/formmode/card/docUpload?detailtype=" + fieldtype + "&category=" + categoryStr + "&mainId=" + main + "&subId=" + sub + "&secId=" + sec;
                    maxUploadSize = uploadMap.maxUploadSize;                        
                    baseProps.showBatchLoad = false;
                    baseProps.showClearAll = false;
                    baseProps.uploadUrl = uploadUrl;
                    baseProps.maxUploadSize = maxUploadSize;
                    baseProps.category = {categoryType:uploadMap.categoryType,mainCategory:main,maxUploadSize:maxUploadSize,secCategory:sec,subCategory:sub};
                    baseProps.datas = uploadMap.uploadData.filedatas;
                    baseProps.btnSize = "small";
                    baseProps.autoUpload = "true";
                    baseProps.listType = fieldtype == '2' ? "img" : "list";
                    baseProps.limitType =  fieldtype == "2" ? "jpg,jpeg,png,gif,bmp" :uploadMap.fileFormat === "0" ? "" : uploadMap.fileFormat;
                    baseProps.uploadId = key;                  
                    baseProps.display = true;
                }  
            }
            baseProps.errorMsg = mes;   
    return (
          <div style={{float:'left'}}>
          <WeaUpload  
            {...baseProps}
            viewAttr={parseInt(viewAttr)}
            onChange={this.props.onChange}
            />
        </div>
    )
  }
}
